package spike.db;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import db.Connector;

import aspect.AspectFilter;
import aspect.AspectGenerator;


public class QueryPool {
	Statement stat = null;
	Statement stat1 = null;
	ResultSet rs = null;
	
	public void putPS(String string) throws ClassNotFoundException, SQLException {
		String result = "";
		Connector.getInstance();
		Connection conn = Connector.getConnection();
		stat = conn.createStatement();
		stat.executeUpdate("update rawtweets set label = 'PS' where seq = " + Integer.valueOf(string) + ";");
		conn.close();
	}

	public void putNG(String string) throws ClassNotFoundException, SQLException {
		String result = "";
		Connector.getInstance();
		Connection conn = Connector.getConnection();
		stat = conn.createStatement();
		stat.executeUpdate("update rawtweets set label = 'NG' where seq = " + Integer.valueOf(string) + ";");
		conn.close();
	}
	
	public void positiveWordCount(int count, String string) throws ClassNotFoundException, SQLException {
		String result = "";
		Connector.getInstance();
		Connection conn = Connector.getConnection();
		stat = conn.createStatement();
		stat.executeUpdate("update positive set count = " + count + " where word = '" + string + "';");
		conn.close();
	}
	
	public void negativeWordCount(int count, String string) throws ClassNotFoundException, SQLException {
		String result = "";
		Connector.getInstance();
		Connection conn = Connector.getConnection();
		stat = conn.createStatement();
		stat.executeUpdate("update negative set count = " + count + " where word = '" + string + "';");
		conn.close();
	}

	
	public ArrayList search(String search) throws ClassNotFoundException, SQLException {
			ArrayList result = new ArrayList();			

			Connector.getInstance();
			Connection conn = Connector.getConnection();
			stat = conn.createStatement();
			rs = stat.executeQuery("select seq, text from rawtweets where lower(text) like '%" + search + "%';");
			while ( rs.next() ) {
				result.add(rs.getString(1));
			}
			conn.close();
			return result;
		}	
		
		public ArrayList selectPosotiveWords() throws ClassNotFoundException, SQLException {
			ArrayList result = new ArrayList();

			Connector.getInstance();
			Connection conn = Connector.getConnection();
			stat = conn.createStatement();
			rs = stat.executeQuery("select word from positive;");
			while ( rs.next() ) {
				result.add(rs.getString(1));
				
			}
			conn.close();
			return result; 
		}	
		
		public ArrayList selectNegativeWords() throws ClassNotFoundException, SQLException {
			ArrayList result = new ArrayList();

			Connector.getInstance();
			Connection conn = Connector.getConnection();
			stat = conn.createStatement();
			rs = stat.executeQuery("select word from negative;");
			while ( rs.next() ) {
				result.add(rs.getString(1));
				
			}
			conn.close();
			return result; 
		}	
		
}